//
//  priorityQueue.swift
//  heap
//
//  Created by lhc on 2024/8/9.
//

import Foundation

/// 优先队列
///
/// 内部是一个最大堆
class PriorityQueue<E: Comparable>: Queue {
    
    private var maxHeap = MaxHeap<E>()
    
    
    func getSize() -> Int {
        return self.maxHeap.getSize()
    }
    
    func isEmpty() -> Bool {
        return self.maxHeap.isEmpty()
    }
    
    func enqueue(e: E) {
        self.maxHeap.add(element: e)
    }
    
    func dequeue() -> E? {
        return try? self.maxHeap.extractMax()
    }
    
    func getFront() -> E? {
        return try? self.maxHeap.findMax()
    }
    
    
    
    
}
